home *** CD-ROM | disk | FTP | other *** search
- Path: newshost.lanl.gov!usenet
- From: luke@raj2.tn.cornell.edu (Luke Emmert)
- Newsgroups: comp.sys.amiga.programmer
- Subject: manipulating the stack in C
- Date: 25 Jan 1996 16:27:44 GMT
- Organization: Los Alamos National Laboratory
- Sender: -Not-Authenticated-[6486]
- Message-ID: <4e8b20$lsq@newshost.lanl.gov>
- NNTP-Posting-Host: scan-o-matic.mst.lanl.gov
- X-Posted-From: InterNews 1.0.8@scan-o-matic.mst.lanl.gov
- Xdisclaimer: No attempt was made to authenticate the sender's name.
-
- I'm currently writing an assembly function that takes a variable
- number of arguments. The last of the arguments is indicated by forcing
- the stack to point at itself(a low probability occurence so I hope).
- The function is called from C code and I therefore need to get C to do
- something weird with the stack. Unfortunately, I need to make
- assumptions about how the compiler will produce binary.
-
- The code looks like the following:
-
- #define LAST_ARG (get_stack())
-
- foo( arg1, arg2, arg3, arg4, LAST_ARG );
-
- where get_stack() simply returns the current
- stack value:
-
- _get_stack:
- move.l a7,d0
- rts
-
- The problem arose last night, when I removed a printf() statement
- that I used for debugging. After disassembling the binary I found that
- the stack was loaded in different ways in each case. My program
- assumes a particular way of loading the stack and that's why it failed.
-
- What I'd like to do is have something in-line that loads the current
- stack value rather like
- move.l a7,(a7)
- without having to use a function call. I'm currently using SAS C v5.10
- and I'm pretty sure that this cannot be done, but if any one has a
- suggestion I would appreciate it.
-
- thank you,
- -luke
-
- * Luke Emmert 'luke@raj2.tn.cornell.edu'
-